package xddq

import (
	"fmt"
	D "websocket_apn/define"
	"websocket_apn/log"
	"websocket_apn/proto"
)

//判断冒险妖怪是否需要切换装备抗性
func (xd *XdDriver) CheckMonsterInfoData(info D.MonsterInfo, cmd int) {
	maxAttr := int64(0)
	maxIdx := 0
	str := ""
	for i := 5; i <= 10; i++ {
		if _, ok := info.Data[i]; ok {
			if info.Data[i].Litter > maxAttr {
				maxAttr = info.Data[i].Litter
				maxIdx = i
			}
		}
		str += fmt.Sprintf("%s:%.1f%% ", D.GetAttrDesc(i), float32(info.Data[i].Litter)/10)
	}
	if cmd == proto.S_STAGE_VIEW_MONSTER_ATTR_RSP {
		log.Infof("冒险妖怪信息: %s", str)
		xd.UserData.FightInfo.MaoXianAttr <- maxIdx
	} else if cmd == proto.S_TOWER_VIEW_MONSTER_ATTR_RSP {
		log.Infof("镇妖塔妖怪信息: %s", str)
		xd.UserData.FightInfo.ZhenYaoTaAttr <- maxIdx
	} else if cmd == proto.S_SECRETTOWER_VIEWMONSTER_RSP {
		log.Infof("真火秘境妖物的信息: %s", str)
		xd.UserData.FightInfo.ZhenHuoMiJingAttr <- maxIdx
	}
}

//处理征战诸天信息结果
func (xd *XdDriver) CheckSkyWarInfoData(allInfo D.SkyWarInfo) {
	xd.UserData.FightInfo.SkyWar <- allInfo
}

//处理星宿试炼怪物信息
func (xd *XdDriver) CheckStartTrialInfoData(info D.StartTrialInfo) {
	if info.FightCount <= 0 || info.FightCount == 255 {
		log.Infof("星宿试炼-结束挑战，无剩余挑战次数")
		xd.StopTaskByID(proto.S_STARTRIAL_EnterMainPanel)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_STARTRIAL_GetDailyFightReward, ""))
		return
	}
	if len(info.ID) > 2 {
		log.Infof("星宿试炼-开始挑战，剩余挑战次数%d次，怪物妖力%s", info.FightCount, D.GetCombatValueDesc(info.CombatValue))
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_STARTRIAL_Fight, fmt.Sprintf("08 %s", info.ID)))
	}
}
